package com.zxl.controller;

import com.zxl.service.ESService;
import com.zxl.vo.Goods;
import com.zxl.vo.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @packageName com.zxl.controller
 * @ClassName
 * @Author zxl
 * @Description //TODO
 * @date
 **/
@Controller
@RequestMapping("/es")
public class GoodsController {

    @Autowired
    private ESService esService;

    @RequestMapping("/save")
    @ResponseBody
    public String save(@RequestBody List<Goods> goods) throws Exception {
        esService.addAll(goods);
        return "su";
    }

    @RequestMapping("/search")
    public String search(Model model, Param param) throws IOException {
        List<Goods> list = esService.list(param);
        model.addAttribute("goodsList",list);
        return "goods-list";
    }



}
